# include 
include Rules.make
include odin_inc

# env
export PKG_CONFIG_PATH=/home/zhaochenhui/pjproject-2.9/build_result/lib/pkgconfig:/home/zhaochenhui/aarch64_search_libs/osip/arm_target/lib/pkgconfig:$PKG_CONFIG_PATH


SDK_DIR=

# Compiler name (with path, if not in path)

LIBS=
XML_LIB = $(OPEN_LIB_DIR)/xml/tx1/lib/libxml.a
XML_LIB += $(OPEN_LIB_DIR)/json-c-0.13/tx1/lib/libjson-c.a

# Mainly used for include paths
INCLUDES=-I inc \
			   -I suma_sip \
			   
INCLUDES += $(ODIN_INC_C_FLAG)

LDFLAGS = `pkg-config --libs libpjproject`
LDFLAGS += `pkg-config --libs libosip2`  -leXosip2
LDFLAGS += $(ODIN_STATIC_LIBS) 
LDFLAGS += $(XML_LIB)
LDFLAGS += -lpthread -lrt -ldl -lz

CFLAGS += -g -Wall -Wwrite-strings  #-Werror -O2
CFLAGS += `pkg-config --cflags libpjproject`
CFLAGS += `pkg-config --cflags libosip2` 

SRC=src
SUMA_SRC=suma_sip
SOURCES= $(wildcard $(SRC)/*.cpp)
SOURCES2= $(wildcard $(SRC)/*.c)
SUMA_SOURCES=$(wildcard $(SUMA_SRC)/*.c)
DIR_OBJS=obj
DIR_BIN=bin
OBJECTS = $(patsubst $(SRC)/%.cpp,$(DIR_OBJS)/%.o, $(SOURCES))
OBJECTS += $(patsubst $(SRC)/%.c,$(DIR_OBJS)/%.o, $(SOURCES2))
OBJECTS += $(patsubst $(SUMA_SRC)/%.c,$(DIR_OBJS)/%.o, $(SUMA_SOURCES))
EXECUTABLE=my_pjsua2_demo
EXECUTABLE:=$(addprefix $(DIR_BIN)/, $(EXECUTABLE))

all: $(SUMA_SOURCES) $(SOURCES) $(SOURCES2) $(OBJECTS) $(EXECUTABLE) 

.PHONY : clean

$(EXECUTABLE): $(OBJECTS) $(LIBS)
	mkdir -p $(dir $@)
	$(CXX)  $^ -o  $@ $(LDFLAGS)

$(DIR_OBJS)/%.o : $(SRC)/%.cpp
	mkdir -p $(dir $@)
	$(CXX) $(INCLUDES) $(DEFINES) -c $(CFLAGS) $< -o $@
	
$(DIR_OBJS)/%.o : $(SRC)/%.c
	mkdir -p $(dir $@)
	$(CC) $(INCLUDES) $(DEFINES) -c $(CFLAGS) $< -o $@
	
$(DIR_OBJS)/%.o : $(SUMA_SRC)/%.c
	mkdir -p $(dir $@)
	$(CC) $(INCLUDES) $(DEFINES) -c $(CFLAGS) $< -o $@


clean:
	rm -fr *.o $(EXECUTABLE)
	rm -fr $(OBJECTS)
	rm -rf $(DIR_BIN) $(DIR_OBJS)	
